# -*- encoding: utf-8 -*-
'''
Filename         :kthSmallest.py
Description      :
Time             :2022/08/01 09:07:18
Author           :daiyizheng
Email            :387942239@qq.com
Version          :1.0
'''

from typing import Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
class Solution:
    def kthSmallest(self, root: Optional[TreeNode], k: int) -> int:
        #         ## 中序遍历是一个递增的数组
        arr = []
        def inorder(root):
            if root is None:
                return []
            
            if root.left is not None:
                inorder(root.left)
            arr.append(root.val)

            if root.right is not None:
                inorder(root.right)
        inorder(root)
        return arr[k-1]